*** Table 5 ***	

use "$data/simulated_df.dta", clear 

est clear

foreach var in any_post_total_patent any_post_total_hi_orig ///
	any_post_total_hi_cite any_post_total_fpds_over50k ///
	post_any_vc any_post_total_allsbir_diff {
		
		if "`var'"=="any_post_total_patent" {
			local stub "pat"
			local head "Patent"
			local yr "1095"
		}
		if "`var'"=="any_post_total_fpds_over50k" {
			local stub "fpds"
			local head "Non-SBIR Contract"
			local yr "1095"
		}
		if "`var'"=="post_any_vc" {
			local stub "vc"
			local head "VC"
			local yr "1095"
		}
		if "`var'"=="any_post_total_hi_orig" {
			local stub "orig"
			local head "High Originality"
			local yr "1095"
		}
		if "`var'"=="any_post_total_allsbir_diff" {
			local stub "allsbir"
			local yr ""
		}
		if "`var'"=="any_post_total_hi_cite" {
			local stub "cite"
			local yr "1095"
		}
		
		qui eststo sp`stub'1: areg `var'`yr' i.select##i.non_specific c.rank_v2_win##i.non_specific ///
			c.rank_v2_lose##i.non_specific c.total_score_orig  ///
			[aweight=weight] if open==0 & phase==1, ///
			cluster(topic_n) absorb(topic_n)
		estadd scalar R= e(r2): sp`stub'1
		estadd local pd "2003-19": sp`stub'1
		estadd local prop "All": sp`stub'1
		estadd local techfe "No": sp`stub'1
		estadd local controls "No": sp`stub'1
		qui sum `var'`yr' if $conv_all
		estadd scalar ymean = r(mean): sp`stub'1
		
		qui eststo sp`stub'2: areg `var'`yr' i.select##i.non_specific  i.select##i.num_prop_p50  c.rank_v2_win##i.non_specific ///
			c.rank_v2_lose##i.non_specific c.total_score_orig employees_at_app age i.full_tag_n25  ///
			[aweight=weight] if open==0 & phase==1, ///
			cluster(topic_n) absorb(topic_n)
		estadd scalar R= e(r2): sp`stub'2
		estadd local pd "2003-19": sp`stub'2
		estadd local prop "All": sp`stub'2
		estadd local techfe "Yes": sp`stub'2
		estadd local controls "Yes": sp`stub'2
		qui sum `var'`yr' if $conv_all 
		estadd scalar ymean = r(mean): sp`stub'2
	}
	

esttab spfpds1 spvc1 sppat1 sporig1 spcite1 spallsbir1 using ///
	"$tables/table5a.tex", ///
	$general $labels keep(1.select 1.select#1.non_specific) ///
	scalars("controls Controls" "techfe Narrow Tech FE" "prop Proposal" ///
		    "pd Time Period" "ymean Outcome Mean") ///
	postfoot("\midrule \end{tabular} \end{footnotesize} ") ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{footnotesize} \begin{tabular}{l*{6}{>{\centering\arraybackslash}p{0.09\textwidth}}}  \toprule \multicolumn{7}{c}{Panel A: No Controls} \\ \midrule & \multicolumn{1}{c}{$\mathbbm{1}$(DoD}& \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(VC)}} & \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(Patent)}} & \multicolumn{1}{c}{$\mathbbm{1}$(High} & \multicolumn{1}{c}{$\mathbbm{1}$(High} & \multicolumn{1}{c}{$\mathbbm{1}$($> 2$} \\ & \multicolumn{1}{c}{Contract)} &  & & \multicolumn{1}{c}{Orig Pat)}  & \multicolumn{1}{c}{Cite Pat)} & \multicolumn{1}{c}{SBIR)} \\ \cmidrule(lr){2-2}  \cmidrule(lr){3-3}  \cmidrule(lr){4-4} \cmidrule(lr){5-5} \cmidrule(lr){6-6} \cmidrule(lr){7-7} ")

esttab spfpds2 spvc2 sppat2 sporig2 spcite2 spallsbir2 using ///
	"$tables/table5b.tex", ///
	$general $labels keep(1.select 1.select#1.non_specific) ///
	scalars("controls Controls" "techfe Narrow Tech FE" "prop Proposal" ///
		    "pd Time Period" "ymean Outcome Mean") ///
	postfoot("\bottomrule \end{tabular} \end{footnotesize} ") ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{footnotesize} \begin{tabular}{l*{6}{>{\centering\arraybackslash}p{0.09\textwidth}}} \multicolumn{7}{c}{Panel B: Controls \& Narrow Technology FE} \\ \midrule & \multicolumn{1}{c}{$\mathbbm{1}$(DoD}  & \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(VC)}} & \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(Patent)}} & \multicolumn{1}{c}{$\mathbbm{1}$(High} & \multicolumn{1}{c}{$\mathbbm{1}$(High} & \multicolumn{1}{c}{$\mathbbm{1}$($> 2$} \\ & \multicolumn{1}{c}{Contract)} & &  & \multicolumn{1}{c}{Orig Pat)}  & \multicolumn{1}{c}{Cite Pat)} & \multicolumn{1}{c}{SBIR)} \\ \cmidrule(lr){2-2}  \cmidrule(lr){3-3}  \cmidrule(lr){4-4} \cmidrule(lr){5-5} \cmidrule(lr){6-6} \cmidrule(lr){7-7} ")
		
